﻿
namespace Inovout.Data.Redis
{
    public class StringCommand : RedisCommand
    {
        public RedisCommandResult<bool> Set(string key, byte[] value, long expirySeconds)
        {
            RedisCommandResult<bool> commandResult = null;
            using (RedisTransaction transaction = Connection.BeginTransaction())
            {
                Execute<bool>(RedisLiteral.Set,key, value);
                Connection.CreateKeyCommand().Expire(key,expirySeconds);
                transaction.Commit();
            }
            return commandResult;
        }


        public string Get(string key, long expirySeconds)
        {
            RedisCommandResult<string> commandResult = null;
            using (RedisTransaction transaction = Connection.BeginTransaction())
            {
               commandResult= Execute<string>(RedisLiteral.Get, key);
                Connection.CreateKeyCommand().Expire(key, expirySeconds);
                transaction.Commit();
            }
            return commandResult.CommandScript.CommandResult.Content.ToString();
        }
    }
}
